package top.gugulh.jx.service.impl;

import cn.hutool.core.lang.generator.SnowflakeGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.gugulh.jx.mapper.UsersMapper;
import top.gugulh.jx.pojo.Users;
import top.gugulh.jx.service.UsersService;

/**
* @author GuguLH
* @description 针对表【users】的数据库操作Service实现
* @createDate 2023-11-21 22:07:39
*/
@Service
public class UsersServiceImpl implements UsersService{

    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private SnowflakeGenerator snowflakeGenerator;

    @Override
    public boolean searchUsernameExist(String username) {
        Users user = usersMapper.selectUserByUsername(username);
        return user != null;
    }

    @Override
    public Users searchUserByUsernameAndPwd(String username, String pwd) {
        return usersMapper.selectUserByUsernameAndPwd(username, pwd);
    }

    @Override
    public Users createUser(Users user) {
        // TODO 生成唯一二维码
        user.setQrcode("");
        user.setId(snowflakeGenerator.next().toString());

        usersMapper.insertUser(user);
        return user;
    }
}




